3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
22 * Form to edit user preferences.
26 class PreferencesFormOOUI
extends OOUIHTMLForm
{
27 // Override default value from HTMLForm
28 protected $mSubSectionBeforeFields = false;
30 private $modifiedUser;
35 public function setModifiedUser( $user ) {
36 $this->modifiedUser
= $user;
42 public function getModifiedUser() {
43 if ( $this->modifiedUser
=== null ) {
44 return $this->getUser();
46 return $this->modifiedUser
;
51 * Get extra parameters for the query string when redirecting after
56 public function getExtraSuccessRedirectParameters() {
64 function wrapForm( $html ) {
65 $html = Xml
::tags( 'div', [ 'id' => 'preferences' ], $html );
67 return parent
::wrapForm( $html );
73 function getButtons() {
74 if ( !$this->getModifiedUser()->isAllowedAny( 'editmyprivateinfo', 'editmyoptions' ) ) {
78 $html = parent
::getButtons();
80 if ( $this->getModifiedUser()->isAllowed( 'editmyoptions' ) ) {
81 $t = $this->getTitle()->getSubpage( 'reset' );
83 $html .= new OOUI\
ButtonWidget( [
85 'id' => 'mw-prefs-restoreprefs',
86 'label' => $this->msg( 'restoreprefs' )->text(),
87 'href' => $t->getLinkURL(),
88 'flags' => [ 'destructive' ],
92 $html = Xml
::tags( 'div', [ 'class' => 'mw-prefs-buttons' ], $html );
99 * Separate multi-option preferences into multiple preferences, since we
100 * have to store them separately
104 function filterDataForSubmit( $data ) {
105 foreach ( $this->mFlatFields
as $fieldname => $field ) {
106 if ( $field instanceof HTMLNestedFilterable
) {
107 $info = $field->mParams
;
108 $prefix = $info['prefix'] ??
$fieldname;
109 foreach ( $field->filterDataForSubmit( $data[$fieldname] ) as $key => $value ) {
110 $data["$prefix$key"] = $value;
112 unset( $data[$fieldname] );
119 protected function wrapFieldSetSection( $legend, $section, $attributes, $isRoot ) {
120 // to get a user visible effect, wrap the fieldset into a framed panel layout
122 // Mimic TabPanelLayout
123 $wrapper = new OOUI\
PanelLayout( [
125 'scrollable' => true,
126 // Framed and padded for no-JS, frame hidden with CSS
128 'infusable' => false,
129 'classes' => [ 'oo-ui-stackLayout oo-ui-indexLayout-stackLayout' ]
131 $layout = new OOUI\
PanelLayout( [
133 'scrollable' => true,
134 'infusable' => false,
135 'classes' => [ 'oo-ui-tabPanelLayout' ]
137 $wrapper->appendContent( $layout );
139 $wrapper = $layout = new OOUI\
PanelLayout( [
143 'infusable' => false,
147 $layout->appendContent(
148 new OOUI\
FieldsetLayout( [
150 'infusable' => false,
153 'content' => new OOUI\
HtmlSnippet( $section )
162 * Get the whole body of the form.
166 // Construct fake tabs to avoid FOUC. The structure mimics OOUI's tabPanelLayout.
167 // TODO: Consider creating an infusable TabPanelLayout in OOUI-PHP.
169 foreach ( $this->getPreferenceSections() as $i => $key ) {
175 'oo-ui-widget oo-ui-widget-enabled oo-ui-optionWidget ' .
176 'oo-ui-tabOptionWidget oo-ui-labelElement' .
177 ( $i === 0 ?
' oo-ui-optionWidget-selected' : '' )
182 'class' => 'oo-ui-labelElement-label',
183 // Make this a usable link instead of a span so the tabs
184 // can be used before JS runs
185 'href' => '#mw-prefsection-' . $key
187 $this->getLegend( $key )
191 $fakeTabsHtml = Html
::rawElement(
193 [ 'class' => 'oo-ui-layout oo-ui-panelLayout oo-ui-indexLayout-tabPanel' ],
196 [ 'class' => 'oo-ui-widget oo-ui-widget-enabled oo-ui-selectWidget ' .
197 'oo-ui-selectWidget-depressed oo-ui-tabSelectWidget' ],
202 return Html
::rawElement(
204 [ 'class' => 'oo-ui-layout oo-ui-panelLayout oo-ui-panelLayout-framed mw-prefs-faketabs' ],
207 [ 'class' => 'oo-ui-layout oo-ui-menuLayout oo-ui-menuLayout-static ' .
208 'oo-ui-menuLayout-top oo-ui-menuLayout-showMenu oo-ui-indexLayout' ],
211 [ 'class' => 'oo-ui-menuLayout-menu' ],
216 [ 'class' => 'oo-ui-menuLayout-content mw-htmlform-autoinfuse-lazy' ],
217 $this->displaySection( $this->mFieldTree
, '', 'mw-prefsection-' )
224 * Get the "<legend>" for a given section key. Normally this is the
225 * prefs-$key message but we'll allow extensions to override it.
229 function getLegend( $key ) {
230 $aliasKey = ( $key === 'optoutwatchlist' ||
$key === 'optoutrc' ) ?
'opt-out' : $key;
231 $legend = parent
::getLegend( $aliasKey );
232 Hooks
::run( 'PreferencesGetLegend', [ $this, $key, &$legend ] );
237 * Get the keys of each top level preference section.
238 * @return array of section keys
240 function getPreferenceSections() {
241 return array_keys( array_filter( $this->mFieldTree
, 'is_array' ) );